/*     */ package com.qmsk.business.wechat.service;
/*     */ 
/*     */ import com.qmsk.business.keyword.keyWord.dao.KeyWordDAO;
/*     */ import com.qmsk.business.manage.cust.dao.CustDAO;
/*     */ import com.qmsk.business.manage.cust.dao.CustShopDAO;
/*     */ import com.qmsk.business.member.member.dao.MemberDAO;
/*     */ import com.qmsk.business.member.memberIntegralBill.dao.MemberIntegralBillDao;
/*     */ import com.qmsk.business.member.memberIntegralDetail.dao.MemberIntegralDetailDAO;
/*     */ import com.qmsk.business.member.memberIntegralRule.dao.MemberIntegralRuleDAO;
/*     */ import com.qmsk.business.member.memberLevel.dao.MemberLevelDAO;
/*     */ import com.qmsk.business.member.memberWx.dao.MemberWxDAO;
/*     */ import com.qmsk.business.member.shopMember.dao.ShopMemberDAO;
/*     */ import com.qmsk.business.message.customerMessageType.dao.CustomerMessageTypeDAO;
/*     */ import com.qmsk.business.message.message.dao.MessageDAO;
/*     */ import com.qmsk.business.shopList.ShopMap;
/*     */ import com.qmsk.business.wechat.dao.MessageRecordDAO;
/*     */ import com.qmsk.business.weixin.customMenu.customer.CustomerInfo;
/*     */ import com.qmsk.business.weixin.customMenu.weiXinUtil.WeiXinUtil;
/*     */ import com.qmsk.business.weixin.customMenu.wxMapUtils.WxMapUtils;
/*     */ import com.qmsk.business.weixin.infoMation.message.resp.Article;
/*     */ import com.qmsk.business.wxdownload.dao.WxCustomerReplayMsgDAO;
/*     */ import com.utils.basic.CDateTimeComm;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.gson.out.GsonEbRstData;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Service;
/*     */ 
/*     */ @Service
/*     */ public class WechatService
/*     */ {
/*  41 */   private static Logger logger = Logger.getLogger(WechatService.class);
/*     */ 
/*     */   @Autowired
/*     */   private CustomerMessageTypeDAO customerMessageTypeDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MessageDAO messageDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MessageRecordDAO messageRecordDAO;
/*     */ 
/*     */   @Autowired
/*     */   private KeyWordDAO keyWordDAO;
/*     */ 
/*     */   @Autowired
/*     */   private WxCustomerReplayMsgDAO wxCustomerReplayMsgDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberWxDAO memberWxDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDAO memberDao;
/*     */ 
/*     */   @Autowired
/*     */   private CustDAO custDao;
/*     */ 
/*     */   @Autowired
/*     */   private CustShopDAO custShopDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberLevelDAO memberLeveldao;
/*     */ 
/*     */   @Autowired
/*     */   private ShopMemberDAO shopMemberDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralRuleDAO memberIntegralRuleDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralBillDao memberIntegralBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralDetailDAO integralDetailDAO;
/*     */ 
/*     */   public boolean sendSubMessage(String openId) { try { GsonEbRst sendMessage = null;
/*     */ 
/*  83 */       int num = this.customerMessageTypeDAO.getSubNum(openId);
/*  84 */       logger.debug("num: " + num);
/*     */ 
/*  87 */       if (num > 0)
/*     */       {
/*  89 */         sendMessage = this.messageDAO.findSubMessageDetail(openId);
/*     */       }
/*     */       else {
/*  92 */         sendMessage = this.messageDAO.findAllMessageDetail(openId);
/*     */       }
/*     */ 
/*  95 */       if ((sendMessage == null) || (sendMessage.getResult() == null) || 
/*  96 */         (sendMessage.getResult().getLen().longValue() == 0L)) {
/*  97 */         logger.debug("no message to send!");
/*  98 */         DbConnection.rollback();
/*  99 */         return true;
/*     */       }
/*     */ 
/* 103 */       List data = sendMessage.getResult().getData();
/* 104 */       List news = new ArrayList();
/* 105 */       int len = data.size();
/* 106 */       for (int i = 0; i < len; ++i) {
/* 107 */         Long messageId = (Long)sendMessage.getResult().getValueOfIdx(
/* 108 */           i, "messageId");
/* 109 */         logger.debug("messageId:" + messageId);
/* 110 */         String title = (String)sendMessage.getResult().getValueOfIdx(
/* 111 */           i, "title");
/* 112 */         String content = (String)sendMessage.getResult()
/* 113 */           .getValueOfIdx(i, "content");
/* 114 */         String imageUrl = (String)sendMessage.getResult()
/* 115 */           .getValueOfIdx(i, "imageUrl");
/* 116 */         String url = (String)sendMessage.getResult().getValueOfIdx(i, 
/* 117 */           "url");
/* 118 */         Article article = new Article();
/* 119 */         article.setSendNewsTitle(title);
/* 120 */         article.setSendNewsDescription(content);
/* 121 */         article.setSendNewsPicUrl(imageUrl);
/* 122 */         if (StringUtils.isNotEmpty(url)) {
/* 123 */           url = url + "?shopId=280000022&openId=" + openId;
/*     */         }
/* 125 */         article.setSendNewsUrl(url);
/* 126 */         news.add(article);
/* 127 */         String[] head = { "messageId", "openId", 
/* 128 */           "createFileTime", "status" };
/* 129 */         Object[] list = { messageId, openId, new Date(), Integer.valueOf(0) };
/* 130 */         GsonHeadOneRow row = new GsonHeadOneRow(head, list);
/*     */ 
/* 133 */         int m = this.messageRecordDAO.insertGsonHeadOneRow(row);
/* 134 */         if (m > 0) {
/* 135 */           logger.debug("message record success!");
/*     */         } else {
/* 137 */           DbConnection.rollback();
/* 138 */           return false;
/*     */         }
/*     */ 
/* 141 */         m = this.messageDAO.updateMessageSendCount(messageId);
/* 142 */         if (m > 0) {
/* 143 */           logger.debug("update message count success!");
/*     */         } else {
/* 145 */           DbConnection.rollback();
/* 146 */           return false;
/*     */         }
/*     */ 
/*     */       }
/*     */ 
/* 151 */       int n = WeiXinUtil.sendNewsMessageOfMain(news, openId);
/* 152 */       if (n != 0) {
/* 153 */         logger.debug("send failed!");
/* 154 */         DbConnection.rollback();
/*     */       } else {
/* 156 */         logger.debug("send successed!");
/*     */       }
/*     */ 
/* 160 */       DbConnection.commit();
/*     */     } catch (Exception e) {
/* 162 */       DbConnection.rollback();
/* 163 */       logger.error("推送微信订阅消息失败，错误信息：" + e);
/* 164 */       logger.error("推送微信订阅消息失败，错误信息：" + e.getMessage());
/*     */     }
/* 166 */     return true;
/*     */   }
/*     */ 
/*     */   public void sendKeyWordReplyMessage(String openId, String text)
/*     */   {
/*     */     try
/*     */     {
/* 179 */       GsonHeadOneRow g = this.keyWordDAO.getReply(text);
/*     */ 
/* 181 */       if ((g == null) || (!(g.isExistsData())) || (g.getDataLength() == 0)) {
/* 182 */         g = this.keyWordDAO.getReply("默认");
/*     */       }
/*     */ 
/* 185 */       if ((g == null) || (!(g.isExistsData())) || (g.getDataLength() == 0)) {
/* 186 */         return;
/*     */       }
/*     */ 
/* 189 */       String content = (String)g.getValueOfName("content");
/* 190 */       String imageUrl = (String)g.getValueOfName("imageUrl");
/* 191 */       String url = (String)g.getValueOfName("url");
/*     */ 
/* 194 */       content = content.replaceAll("OPENID", openId);
/*     */ 
/* 197 */       if ((StringUtils.isNotEmpty(imageUrl)) || (StringUtils.isNotEmpty(url))) {
/* 198 */         List news = new ArrayList();
/* 199 */         Article article = new Article();
/* 200 */         article.setSendNewsTitle("回复");
/* 201 */         article.setSendNewsDescription(content);
/* 202 */         article.setSendNewsPicUrl(imageUrl);
/* 203 */         if (StringUtils.isNotEmpty(url)) {
/* 204 */           url = url + "?shopId=280000022&openId=" + openId;
/*     */         }
/* 206 */         article.setSendNewsUrl(url);
/* 207 */         news.add(article);
/* 208 */         WeiXinUtil.sendNewsMessageOfMain(news, openId);
/* 209 */         return; }
/* 210 */       WeiXinUtil.sendTextMessageOfMain(content, openId);
/*     */     }
/*     */     catch (Exception e) {
/* 213 */       DbConnection.rollback();
/* 214 */       logger.error("关键字过滤发送消息失败，错误信息：" + e);
/* 215 */       logger.error("关键字过滤发送消息失败，错误信息：" + e.getMessage());
/*     */     }
/*     */   }
/*     */ 
/*     */   public void saveTextInfo(String openId, String content)
/*     */   {
/*     */     try
/*     */     {
/* 229 */       String openName = null;
/*     */       try {
/* 231 */         CustomerInfo custInfo = WxMapUtils.getCustInfoOfOpenId(openId);
/* 232 */         openName = custInfo.getNickname();
/*     */       } catch (Exception e) {
/* 234 */         logger.error("获取用户昵称出错，openId:" + openId);
/*     */       }
/* 236 */       if ((openName == null) || (openId == null))
/*     */         return;
/* 238 */       GsonHeadOneRow g = new GsonHeadOneRow(new String[0], 
/* 239 */         new Object[0]);
/* 240 */       Date date = new Date();
/* 241 */       g.addHeadData("OpenID", openId);
/* 242 */       g.addHeadData("OpenName", openName);
/* 243 */       g.addHeadData("msgTypId", Integer.valueOf(1));
/* 244 */       g.addHeadData("creatTime", date);
/* 245 */       g.addHeadData("channelId", Integer.valueOf(0));
/* 246 */       g.addHeadData("content", content);
/* 247 */       int n = this.wxCustomerReplayMsgDAO.insertGsonHeadOneRow(g, 
/* 248 */         "wx_customerreplymsg");
/*     */ 
/* 250 */       if (n > 0) {
/* 251 */         DbConnection.commit();
/* 252 */         return; }
/* 253 */       DbConnection.rollback();
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 257 */       DbConnection.rollback();
/* 258 */       logger.error("保存用户消息失败，错误信息：" + e);
/* 259 */       logger.error("保存用户消息失败，错误信息：" + e.getMessage());
/*     */     }
/*     */   }
/*     */ 
/*     */   public boolean autoShipMember(String openId, Long shopId, String userName)
/*     */   {
/*     */     try
/*     */     {
/* 273 */       int n = 0;
/* 274 */       Integer intAmt = Integer.valueOf(0);
/* 275 */       String nickName = null;
/* 276 */       String memberCardNo = null;
/* 277 */       logger.debug("OpenId:" + openId);
/*     */ 
/* 279 */       if ((StringUtils.isNotEmpty(openId)) && (shopId != null)) {
/* 280 */         GsonHeadOneRow rowMemberLevel = null;
/* 281 */         Long levelId = this.memberWxDao.selectSqlOfDefaultParamsShop(shopId, 
/* 282 */           1);
/* 283 */         logger.debug("LevelId:" + levelId);
/* 284 */         if (levelId != null) {
/* 285 */           rowMemberLevel = this.memberLeveldao.getGsonOfLevelId(levelId);
/*     */         }
/* 287 */         logger.debug("MemberLevel:" + rowMemberLevel);
/* 288 */         Long memberId = null;
/* 289 */         Long custId = null;
/* 290 */         if ((levelId != null) && (rowMemberLevel != null) && 
/* 291 */           (rowMemberLevel.isExistsData())) {
/* 292 */           Date crTime = new Date();
/* 293 */           logger.debug("MemberLevel:" + rowMemberLevel);
/*     */ 
/* 295 */           if (this.memberDao.getIsMemberRgNew(openId, shopId).longValue() > 0L) {
/* 296 */             logger.error("该客户已经关注 ");
/* 297 */             return true;
/*     */           }
/* 299 */           CustomerInfo custInfo = 
/* 300 */             WxMapUtils.getCustInfoOfOpenId(openId);
/* 301 */           String imageUrl = null;
/* 302 */           if (custInfo != null) {
/* 303 */             imageUrl = custInfo.getHeadimgurl();
/* 304 */             nickName = custInfo.getNickname();
/*     */           }
/* 306 */           GsonHeadOneRow rowCustomer = new GsonHeadOneRow(
/* 307 */             new String[] { "name", "openId", "Status", 
/* 308 */             "createTime", "CustFrom", 
/* 309 */             "wxCreateTime", "imageUrl" }, 
/* 310 */             new Object[] { nickName, openId, Integer.valueOf(0), crTime, Integer.valueOf(3), 
/* 311 */             crTime, imageUrl });
/* 312 */           n = this.custDao.insertGsonHeadOneRow(rowCustomer);
/* 313 */           if (n > 0) {
/* 314 */             custId = this.custDao.getLastId();
/* 315 */             if (custId.longValue() > 0L) {
/* 316 */               GsonHeadOneRow s = new GsonHeadOneRow(
/* 317 */                 new String[] { "custId", "shopId" }, 
/* 318 */                 new Object[] { custId, shopId });
/* 319 */               n = this.custShopDao.insertGsonHeadOneRow(s);
/*     */             }
/* 321 */             if ((custId.longValue() > 0L) && (n > 0)) {
/* 322 */               String[] headMember = { "CustID", 
/* 323 */                 "status", "CreateFileTime", "payPwd", 
/* 324 */                 "LevelID", "DepositAmount", 
/* 325 */                 "IntegralAmount", "ConsumeAmount", 
/* 326 */                 "CashCouponAmount", "CouponAmount" };
/* 327 */               Object[] dataMember = { custId, 
/* 328 */                 Integer.valueOf(2), new Date(), 
/* 329 */                 "111111", levelId, Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0) };
/* 330 */               GsonHeadOneRow gMember = new GsonHeadOneRow(
/* 331 */                 headMember, dataMember);
/* 332 */               gMember.encryptHead("payPwd");
/* 333 */               Integer validDay = null;
/* 334 */               Double discount = null;
/* 335 */               if ((levelId != null) && (levelId.longValue() > 0L)) {
/* 336 */                 validDay = 
/* 337 */                   ObjectComm.objectToInteger(rowMemberLevel
/* 338 */                   .getValueOfName("ValidDay"));
/* 339 */                 if (validDay.intValue() <= 0)
/* 340 */                   gMember.autoAddHeadData(
/* 341 */                     "ValidDateTime", 
/* 342 */                     CDateTimeComm.getAddYear(
/* 343 */                     crTime, 100));
/*     */                 else {
/* 345 */                   gMember.autoAddHeadData(
/* 346 */                     "ValidDateTime", 
/* 347 */                     CDateTimeComm.getAddDay(crTime, 
/* 348 */                     validDay.intValue()));
/*     */                 }
/* 350 */                 discount = 
/* 351 */                   ObjectComm.objectToDouble(rowMemberLevel
/* 352 */                   .getValueOfName("discount"));
/* 353 */                 gMember.autoAddHeadData("ValidDay", 
/* 354 */                   validDay);
/* 355 */                 gMember.autoAddHeadData("DisCount", 
/* 356 */                   discount);
/*     */               }
/* 358 */               n = this.memberDao.insertGsonHeadOneRow(gMember);
/* 359 */               memberId = this.memberDao.getLastId();
/* 360 */               if ((n > 0) && (memberId.longValue() > 0L)) {
/* 361 */                 GsonHeadOneRow memberRuleRow = this.memberIntegralRuleDAO
/* 362 */                   .selectgzInfo(shopId, levelId, "关注");
/* 363 */                 logger.error("**********memberRuleRow***22222222222222222******" + 
/* 364 */                   memberRuleRow);
/* 365 */                 if (memberRuleRow != null) {
/* 366 */                   intAmt = 
/* 367 */                     ObjectComm.objectToInteger(memberRuleRow
/* 368 */                     .getValueOfName("FixedIntegral"));
/* 369 */                   if (intAmt.intValue() > 0) {
/* 370 */                     logger.error("**********intAmt***22222222222222222******" + 
/* 371 */                       intAmt);
/* 372 */                     Long ruId = (Long)memberRuleRow
/* 373 */                       .getValueOfName("RuleID");
/* 374 */                     String billNo = this.memberIntegralBillDao
/* 375 */                       .getMaxBillNo(shopId);
/* 376 */                     n = this.memberIntegralBillDao
/* 377 */                       .insertIntegralBill(
/* 378 */                       memberId, shopId, 
/* 379 */                       billNo, ruId, 
/* 380 */                       intAmt, "关注", 
/* 381 */                       crTime, userName, 
/* 382 */                       1, "wx", "关注");
/* 383 */                     if (n > 0) {
/* 384 */                       Long billId = this.memberIntegralBillDao
/* 385 */                         .getLastId();
/* 386 */                       n = this.integralDetailDAO
/* 387 */                         .insertBusBillDtialInAmt(
/* 388 */                         memberId, 
/* 389 */                         shopId, intAmt, 
/* 390 */                         Integer.valueOf(0), billId);
/*     */                     }
/*     */                   } else {
/* 393 */                     logger.error("无可添加的积分");
/*     */                   }
/* 395 */                   memberCardNo = 
/* 396 */                     ShopMap.getCardFlagOfShopId(shopId) + 
/* 397 */                     String.valueOf(memberId);
/* 398 */                   Long groupId = 
/* 399 */                     ShopMap.getGroupIdOfShopId(shopId);
/* 400 */                   gMember.delHead(new String[] { "CustID" });
/* 401 */                   gMember.addHeadData(new String[] { 
/* 402 */                     "MemberID", "ShopID", 
/* 403 */                     "groupId", "IsCreateShop", 
/* 404 */                     "MemberCardNo" }, new Object[] { 
/* 405 */                     memberId, shopId, groupId, Integer.valueOf(1), 
/* 406 */                     memberCardNo });
/*     */ 
/* 408 */                   if (intAmt.intValue() > 0) {
/* 409 */                     gMember.autoAddHeadData(
/* 410 */                       "IntegralAmount", intAmt);
/*     */                   }
/* 412 */                   logger.error("**********intAmt***22222222222222222******" + 
/* 413 */                     intAmt);
/* 414 */                   n = this.shopMemberDAO.insertGsonHeadOneRow(
/* 415 */                     gMember, "crm_shop_member");
/*     */                 }
/*     */               }
/*     */             } else {
/* 419 */               logger.error("自动入会失败！");
/* 420 */               return false;
/*     */             }
/*     */           } else {
/* 423 */             logger.error("自动入会失败！");
/* 424 */             return false;
/*     */           }
/* 426 */           if (n > 0) {
/* 427 */             GsonHeadOneRow a = new GsonHeadOneRow(new String[] { 
/* 428 */               "ShopID", "OpenID", "custName", "Status", 
/* 429 */               "CreateFileTime" }, new Object[] { shopId, 
/* 430 */               openId, nickName, Integer.valueOf(1), crTime });
/* 431 */             n = this.memberWxDao.insertGsonHeadOneRow(a, 
/* 432 */               "crm_memberapply");
/*     */           }
/*     */         }
/*     */         else {
/* 436 */           logger.error("级别没有找到！");
/* 437 */           return false;
/*     */         }
/*     */       } else {
/* 440 */         logger.error("基本信息获取失败！");
/* 441 */         return false;
/*     */       }
/* 443 */       if (intAmt.intValue() <= 0);
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 447 */       DbConnection.rollback();
/* 448 */       logger.error("自动入会失败，错误信息：" + e);
/* 449 */       logger.error("自动入会失败，错误信息：" + e.getMessage());
/* 450 */       return false;
/*     */     }
/* 452 */     return true;
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.wechat.service.WechatService
 * JD-Core Version:    0.5.3
 */